package com.guojian.http.handle;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;

/**
 * 代理流程模板类
 *  1.JettyRequestToTargetRequest
 *  
 *  2.doTargetHttpProsess
 *  
 *  3.TargetResponseToJettyResponse
 *  
 * @author guoJian
 *
 */
public abstract class AbstractJettyProxyHandler<REQ, RES> extends AbstractJettyHandler {

	@Override
	protected void handleJettyRequestResponse(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		RES targetHttpResponse = doHttpClientProcess(jettyRequestToTargetRequestConvert(baseRequest));
		targetHttpResponseToJettyResponseConvert(response, targetHttpResponse);
	}

	protected abstract REQ jettyRequestToTargetRequestConvert(Request baseRequest);

	protected abstract RES doHttpClientProcess(REQ httpUriRequest);

	protected abstract void targetHttpResponseToJettyResponseConvert(HttpServletResponse response, RES targetHttpResponse) throws IOException;

}
